using Command;
using QFramework;
using UnityEngine;

namespace ViewController.Gameplay
{
    public class Bullet : ShootingEditor2DController
    {
        private Rigidbody2D _rigidbody2D;

        private void Awake()
        {
            _rigidbody2D = GetComponent<Rigidbody2D>();

            Destroy(gameObject, 5);
        }

        private void Start()
        {
            _rigidbody2D.velocity = Vector2.right * 10 * Mathf.Sign(transform.localScale.x);
        }

        private void OnCollisionEnter2D(Collision2D col)
        {
            if (col.gameObject.CompareTag("Enemy"))
            {
                this.SendCommand<KillEnemyCommand>();

                Destroy(col.gameObject);

                Destroy(gameObject);
            }
        }
    }
}